package cn.xiaoliu.quartz.job;

import cn.xiaoliu.order.service.IAdoptOrderService;
import cn.xiaoliu.order.service.IProductOrderService;
import cn.xiaoliu.quartz.constant.JobConstants;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

public class MainJob implements Job{
    @Autowired
    private IAdoptOrderService adoptOrderService;
    @Autowired
    private IProductOrderService productOrderService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //获取JobDetail中关联的数据
        Map<String,Object> map = (Map<String, Object>) jobExecutionContext.getJobDetail().getJobDataMap().get("params");
        //拿到传递的业务类型  里面有着不同的业务
        String type = (String) map.get("type");
        switch (type){
            case JobConstants.TIME_OUT_ADOPT_LAST_PAY:{
                Long orderId = (Long)map.get("orderId");//不同的订单
                adoptOrderService.cancelByQuartz(orderId);
                break;
            }
            case JobConstants.TIME_OUT_PRODUCT_LAST_PAY:{
                Long orderId = (Long) map.get("orderId");
                productOrderService.cancelByQuartz(orderId);
                break;
            }
            default:break;
        }

    }
}
